package com.yequan.hbb.view.fragment.tuantuan_page_fragment;


import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import com.yequan.hbb.R;
import com.yequan.hbb.adapter.TuanAdapter;
import com.yequan.hbb.app.MyApplication;
import com.yequan.hbb.entries.TuanTuanEntries;
import com.yequan.hbb.presenter.TuanPresenter;
import com.yequan.hbb.view.TuanView;

/**
 * A simple {@link Fragment} subclass.
 */
public class HelpChoseFragment extends Fragment implements TuanView<TuanTuanEntries>{


    private TuanPresenter presenter;
    private RecyclerView recycler;
    private TuanAdapter<TuanTuanEntries.DataBean.DataBean2> adapter;

    public HelpChoseFragment() {
        // Required empty public constructor
    }

    public static HelpChoseFragment newInstance(String title) {
        Bundle bundle = new Bundle();
        bundle.putString("title",title);
        HelpChoseFragment fragment = new HelpChoseFragment();
        fragment.setArguments(bundle);
        return fragment;
    }
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.fragment_help_chose, container, false);
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        recycler = (RecyclerView) view.findViewById(R.id.chose_recycler);
        adapter = new TuanAdapter<>(view.getContext());
        recycler.setAdapter(adapter);
        presenter = new TuanPresenter();
        presenter.attach(this);
        presenter.getData();
    }

    @Override
    public void showTuan(TuanTuanEntries tuanTuanEntries) {
        Toast.makeText(MyApplication.context, "成功", Toast.LENGTH_LONG).show();
        adapter.addAll(tuanTuanEntries.getData().getData());
        //adapter.start();

    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        presenter.dettch();
    }
}
